package com.kushe.dao;

import com.kushe.entity.Sign;
import com.kushe.util.core.DataAccess;
import com.kushe.util.core.DbUtils;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;

import java.util.List;

/**
 * Created by WSDevotion on 2015/5/30.
 */
public class SignDao {
    public static Sign get(int id) {
        return DbUtils.getNutzDao().fetch(Sign.class, id);
    }


    public static Sign addSign(Sign sign) {
        Dao dao = DbUtils.getNutzDao();
        List<Sign> list = dao.query(Sign.class, Cnd.where("user_id", "=", sign.getUser_id()).where("topic_id", "=", sign.getTopic_id()));
        if (list != null) {
            dao.insert(sign);
            return sign;
        } else
            return null;
    }

    public static Sign getSigns(int user_id, int topic_id) {
        Dao dao = DbUtils.getNutzDao();
        List<Sign> list = dao.query(Sign.class, Cnd.where("user_id", "=", user_id).where("topic_id", "=", topic_id));
        if(list.size()!=0){
            return list.get(0);
        }
        return null;
    }

    public static void delectSigns(int id) {
        Dao dao = DbUtils.getNutzDao();
        dao.delete(Sign.class, id);
    }

}
